package com.elepant.dp.cor;

import java.util.ArrayList;
import java.util.List;

public class FilterChain {

    private int index = 0;
    private List<Filter> filters = new ArrayList<>();

    public FilterChain addFilter(Filter filter) {
        filters.add(filter);
        return this;
    }

    public void doFilter(Request request, Response response) {
        if(index == filters.size()) return;
        Filter filter = filters.get(index);
        index ++;
        filter.doFilter(request,response,this);
    }
}
